home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / po-script-fu / script-fu-xgettext < prev    next >
Encoding:
Text File  |  2000-04-11  |  1.2 KB  |  53 lines

  1. #!/usr/bin/perl
  2.  
  3. # a lame attempt at xgettext for scheme
  4. # adapted from pxgettext as found in the plug-ins/perl directory
  5.  
  6. # TODO:
  7. # proper linenumbers
  8.  
  9. # There are rumors that perl version 5.005_02 has a bug
  10. # resulting in an endless loop and a memory leak in the 
  11. # regex machinery. 
  12. #
  13. # It seems to work however. I'll leave this check commented out until
  14. # people report problems.
  15. #
  16. # die ("Your version of Perl (5.005_02) is broken!\nCan't extract the strings from the scripts.\nA lot of messages will be missing from your gimp-script-fu.pot file.\n\n") if $] eq 5.005_02;
  17.  
  18. undef $/;
  19.  
  20. my $file;
  21. my $fileposition;
  22. my $e;
  23. my $s;
  24.  
  25. while (<>) {
  26.     $file = $ARGV;
  27.     $file =~ s/\.\.\///;
  28.  
  29.     while (/_\(?"((?:[^"\\]+|\\.)*)"\)?/sg) {
  30.         my $s = $1;
  31.         if ($s =~ /\n/) {
  32.             $e = "msgid \"\"\n";
  33.             for (split /\n/, $s) {
  34.                 $e .= "\"$_\\n\"\n";
  35.             }
  36.         } else {
  37.             $e = "msgid \"$s\"\n";
  38.         }
  39.         $e .= "msgstr \"\"\n";
  40.  
  41.         $fileposition = "#: $file:0\n";
  42.  
  43.         push @{$entry{$e}}, $fileposition;
  44.     }
  45. }
  46.  
  47. foreach $e (sort keys %entry) {
  48.     print @{$entry{$e}};
  49.     print $e;
  50.     print "\n";
  51. }
  52.  
  53.